#include <iostream>
#include "CodeDumpVisitor.h"
#include "BinExpr.h"
#include "AddExpr.h"
#include "SubExpr.h"
#include "MulExpr.h"
#include "DivExpr.h"
#include "ConstExpr.h"

CodeDumpVisitor::CodeDumpVisitor(std::ostream& os):m_os(os),m_indent(0)
{
    //ctor
}
void CodeDumpVisitor::Indent(){
    for(int i=0;i<this->m_indent;i++){
        this->m_os<<"    ";
    }
}
void CodeDumpVisitor::DumpChildrenExpr(BinExpr* expr){
    this->Indent();	this->m_os<<expr->Getopstr()<<"["<<std::endl;
    this->m_indent++;
    expr->Getlhs()->Accept(this);
    this->Indent(); this->m_os<<","<<std::endl;
    expr->Getrhs()->Accept(this);
    this->m_indent--;
    this->Indent(); this->m_os<<"]"<<std::endl;
}

void CodeDumpVisitor::Visit(AddExpr* expr){
    DumpChildrenExpr(expr);
};
void CodeDumpVisitor::Visit(SubExpr* expr){
    DumpChildrenExpr(expr);
};
void CodeDumpVisitor::Visit(MulExpr* expr){
    DumpChildrenExpr(expr);
};
void CodeDumpVisitor::Visit(DivExpr* expr){
    DumpChildrenExpr(expr);
};
void CodeDumpVisitor::Visit(ConstExpr* expr){
    this->Indent();this->m_os<<"CONST["<<expr->Getvalue()<<"]"<<std::endl;
}
